package com.neu.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.neu.App;
import com.neu.R;
import com.neu.bean.AllService;
import com.neu.util.VolleyUtil;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class RecServiceAdapter extends RecyclerView.Adapter<RecServiceAdapter.VH> {

    List<AllService.RowsBean> list;

    public RecServiceAdapter(List<AllService.RowsBean> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_home_service_adapter,null);
        return new VH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {
        AllService.RowsBean r=list.get(position);
        holder.tvService.setText(r.getServiceName());
        //获得图片地址
        String url= VolleyUtil.BASE_URL+r.getImgUrl();
        //加载图片
       Glide.with(App.context).load(url).into(holder.imgService);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class VH extends RecyclerView.ViewHolder{
        ImageView imgService;
        TextView tvService;
        public VH(@NonNull View itemView) {
            super(itemView);
            imgService=itemView.findViewById(R.id.imgService);
            tvService=itemView.findViewById(R.id.tvService);
        }
    }

}
